package com.javabasic;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/1/9 11:44 上午
 */
public class VikaTest {

    /**
     * [[1,1,1],[1,2,3],[1,2,3]]
     * [[2,2,2],[2,2,2],[2,2,2]]
     * @param matrix
     * @return
     */
    public boolean checkValid(int[][] matrix) {
        int len = matrix.length, result;
        int[] tag = new int[len+1];

        for (int i = 0; i < len; i++) {
            for (int k = 1; k <= len; k++) {
                tag[k] = 1;
            }
            result = 0;
            for (int j = 0; j < len; j++) {
                if (matrix[i][j] >= 1 && matrix[i][j] <= len && tag[j] == 1) {
                    result += matrix[i][j];
                    tag[j] = 0;
                } else {
                    return false;
                }
            }
            System.out.println(result);
            if (result != (1+len)*len/2) {
                return false;
            }
        }

        for (int i = 0; i < len; i++) {
            for (int k = 1; k <= len; k++) {
                tag[k] = 1;
            }
            result = 0;
            for (int j = 0; j < len; j++) {
                if (matrix[j][i] >= 1 && matrix[j][i] <= len && tag[j] == 1) {
                    result += matrix[j][i];
                    tag[j] = 0;
                } else {
                    return false;
                }
            }
            if (result != (1+len)*len/2) {
                return false;
            }
        }

        return true;
    }
}
